<?php
/**
 * Created by PhpStorm.
 * User: Yueool
 * Date: 2020/3/3
 * Time: 16:33
 */

namespace collecter\data\tasks;



use common\libraries\Collector;

class Hktv8 implements \collecter\components\PageTask {

    public function test(){
        echo "testclass";
    }

    /**
     * @param $page
     * @return array
     */
    public function getTasks($page){
        // TODO: Implement getTasks() method.

        $url = "https://www.hktv8.com/forum-56-".$page.".html";

        $content = file_get_contents($url);

        $content = iconv("gbk","utf-8//IGNORE",$content)  ;
        //echo $content;exit;

        $content = preg_replace("/[\n\r]/", "", $content);//去换行
        $content = preg_replace("/\s+/", " ", $content);//多个空格换成一个
        //echo $content;exit;

        $pattern = '/onclick=\"previewThread\(\'(\d+)\'.*?<a\shref=\"([^<>]*?)\"[^<>]*?class=\"s\sxst\">([^<>]*?)</i';
        preg_match_all($pattern, $content, $matches);

        //echo '<pre>';print_r($matches);

        $data = [];
        foreach($matches[1] as $key => $value){
            $data[$key]["tid"] = $value;
        }
        foreach($matches[2] as $key => $value){
            $data[$key]["link"] = $value;
        }
        foreach($matches[3] as $key => $value){
            $data[$key]["title"] = $value;
        }
        //echo '<pre>';print_r($data);exit;

        return $data;
    }

    /**
     *
     */
    public function getTask($url){
        // TODO: Implement getTask() method.

        //$content = file_get_contents($url);

        $cookieStr = 'vsyQ_8bcf_lastvisit=1654846767; vsyQ_8bcf_seccodecSVS9Q5m=101.109cbdf18cdd91ef69; vsyQ_8bcf_ulastactivity=953egV0MeFVToqw8W%2BvAPI%2FVswJHnbkC5KOFNikMytt6wWW%2F7%2BhO; vsyQ_8bcf_lastcheckfeed=204673%7C1654850375; vsyQ_8bcf_connect_is_bind=0; vsyQ_8bcf_visitedfid=56; vsyQ_8bcf_viewid=tid_36826; vsyQ_8bcf_smile=1D1; vsyQ_8bcf_st_p=204673%7C1654855563%7Cf07402a617ad15c07bac36f640767813; vsyQ_8bcf_noticeTitle=1; vsyQ_8bcf_sid=aWncC6; vsyQ_8bcf_lip=106.121.136.172%2C1654855563; vsyQ_8bcf_checkpm=1; vsyQ_8bcf_sendmail=1; vsyQ_8bcf_lastact=1654856045%09misc.php%09patch';


        $content = Collector::httpscurl($url, [], $cookieStr);



        $content = iconv("gbk","utf-8//IGNORE",$content)  ;
        //echo $content;exit;

        $content = preg_replace("/[\n\r]/", "", $content);//去换行
        $content = preg_replace("/\s+/", " ", $content);//多个空格换成一个
        echo $content;exit;

    }

}